import QtQuick 1.0
import "common"

Item {
    id:root

    property string destPath : ""
    property int activeIndex : -1

    signal connectClicked()
    signal uploadClicked()
    signal returnClicked()



    Text {
        anchors.centerIn: parent
        font.pixelSize: 50
        text:"SERVER"
        opacity: 0.2
        color: "white"
    }


    Header {
        id:header
        anchors.top: root.top
        onReturnClicked: ftpModel.back()
        path: ftpModel.currentPath
    }



    ListView {
        id:view
        anchors.top: header.bottom
        width: root.width
        height: root.height - header.height

        clip:true
        model:ftpModel
       // enabled: ftpModel.state == 4 && !toolBar.show? true : false
        delegate: OMenuItem {
            title: name
            subTitle: Qt.formatDateTime(lastModified,"dd MMM yyyy  hh:mm")
            fileSize:size
            icon:"image://icons/"+name
            active: root.activeIndex == index ? true : false
            animOrientation: 1
            onClicked: {
                if ( isDir)
                    ftpModel.openFolder(index)
                else
                {
                    startAnim()
                    ftpModel.downloadFile(index,root.destPath)
                }
            }

            onPressAndHold: {
                dialog.fileName = name
                dialog.show = true;
                root.activeIndex = index
            }
        }
    }


    FtpDialog {
        id:dialog
        width: root.width
        height: root.height
//        onOpened: console.debug(path)
        onRenamed:  ftpModel.renameFile(root.activeIndex,name);/*systemModel.actionRename(visualModel.modelIndex(view.currentIndex), name)*/
       onMakeDir:  ftpModel.mkdir(name)
       onRemoved: ftpModel.removeFile(root.activeIndex)
    }


}
